package a10_动态规划;

import java.util.Arrays;

/**
 * <p>
 * a41_最长递增子序列复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/28
 */
public class a41_最长递增子序列复习2 {
    public static void main(String[] args) {
        a41_最长递增子序列复习2 test = new a41_最长递增子序列复习2();
        System.out.println(test.lengthOfLIS(new int[]{10, 9, 2, 5, 3, 7, 101, 18}));
    }

    public int lengthOfLIS(int[] nums) {
        int result = 1;//为啥初始化为1,因为如果nums.length=0，那么下面的循环进不去

        int[] dp = new int[nums.length];

        Arrays.fill(dp, 1);

        for (int i = 1; i < nums.length; i++) {
            for (int j = 0; j < i; j++) {
                if(nums[i] > nums[j]){
                    dp[i] = Math.max(dp[i],dp[j]+1);
                }
            }
            System.out.println(Arrays.toString(dp));
            result = Math.max(result, dp[i]);
        }

        return result;


    }
}
